package com.luo.partner.scheduled;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONObject;
import com.luo.partner.dao.model.TabUsrs;
import com.luo.partner.service.TabUsrsService;

@Component
public class MonthlyknotScheduled {
	
	private static final Logger logger = LoggerFactory.getLogger(MonthlyknotScheduled.class);
	
	@Autowired
	TabUsrsService tabUsrsService;
	
//    @Scheduled(cron = "0 0/10 * * * ?")  //每十分钟执行一次
//    @Scheduled(cron = "0/5 * * * * ?")  //每5秒执行一次
    @Scheduled(cron = "0 0 0 1 * ?")  //每月1号
    public void  settlementRecharge() {

    	List<TabUsrs> list = tabUsrsService.findUnSettlementRechargeUserList();
    	if (list == null || list.isEmpty()) {
    		logger.info("上个月没有需要结算的用户");
			return ;
		}
    	
    	for (TabUsrs tabUsrs : list) {
			try {
				tabUsrsService.settlementRecharge(tabUsrs);
				logger.error("结算完成，结算用户：" + tabUsrs.getAccount() + "，结算的金额：" + tabUsrs.getUnSettlementRecharge().toString());
			} catch (RuntimeException e) {
				logger.error("结算有误，原因：" + e.getMessage());
				logger.error("结算有误，结算数据：" + JSONObject.toJSONString(tabUsrs));
			}
		}
    }
    
    
    
    
    
}